package com.sgb.kjwl.view.ui.activity.self.userInfo;

import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityBasicInfoBinding;
import com.sgb.kjwl.view.widget.SexPopWindow;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.util.StringUtil;

public class BasicInfoActivity extends AppActivity {
    private ActivityBasicInfoBinding binding;
    private SexPopWindow sexPopWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void initView() {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        binding = DataBindingUtil.setContentView(BasicInfoActivity.this, R.layout.activity_basic_info);
        binding.phoneTv.setText(StringUtil.gonePhone(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_PHONE, "")));
        int role = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.LOGIN_ROLE, 0);
        if (role == 0) {
            binding.typeTv.setText("普通用户");
        } else if (role == 1) {
            binding.typeTv.setText("采购商");
        } else if (role == 2) {
            binding.typeTv.setText("供应商");
        } else if (role == 3) {
            binding.typeTv.setText("采购商");
        }
        binding.nameTv.setText(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.REAL_NAME, ""));
    }

    @Override
    protected void init() {
        binding.barTitleLayout.ivBack.setOnClickListener(this);
        binding.barTitleLayout.titleView.setText("基本信息");
        binding.rlSex.setOnClickListener(this);

        sexPopWindow = new SexPopWindow(this);
        sexPopWindow.setBgView(binding.grayLayout);
        sexPopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2,Object key3) {
                if ((int) key1 == SexPopWindow.SELECTE_MAN) {
                    binding.tvSex.setText("男");
                } else if ((int) key1 == SexPopWindow.SELECTE_WOMEN) {
                    binding.tvSex.setText("女");
                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.rl_sex:
                sexPopWindow.showDownPopwindow(binding.rlSex, true);
                break;
        }

    }
}
